pluginHome = new File( grailsSettings.projectPluginsDir.path ).listFiles().find { it.name.startsWith('cloud-tools-') }
if(pluginHome == null) pluginHome = "."

includeTargets << new File( "${pluginHome}/scripts/CloudToolsInit.groovy" )

target('default': "Clones the cluster") {
	cloneCluster()
}


target(cloneCluster: "The implementation task") {
	depends( initCloudToolsService)
  	cloudToolsService.withCluster { clusterManager, clusterName, cluster ->
		if(System.getProperty("cloudtools.new.cluster.name") != null){
			def newClusterName = System.getProperty("cloudtools.new.cluster.name")
			clusterManager.cloneCluster(cluster, newClusterName);
			event('StatusFinal', ["Finished cloning cluster"])
		}else{
			event('StatusError', ["A cluster name was not specified.  Example:\ngrails -Dcloudtools.new.cluster.name=<new cluster name> cloud-tools-clone"])
		}
    }
}